<template>
  <div>
    <el-form size="mini" ref="form" :rules="rules" :model="form" label-width="100px">
      <el-form-item label="发布平台" prop="plat_type">
        <el-radio-group v-model="form.plat_type">
          <el-radio :label="0">Feijiu网</el-radio>
          <el-radio :label="1">聚拍网</el-radio>
        </el-radio-group>
      </el-form-item>
      <div v-show="form.plat_type === 0">
        <el-empty description="功能暂未开启"></el-empty>
      </div>
      <div v-show="form.plat_type === 1">
        <el-form-item label="信息简介" prop="title">
          <el-input type="textarea" v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="数量" prop="number">
          <el-input v-model="form.number"></el-input>
        </el-form-item>
        <el-form-item label="联系人" prop="contact_name">
          <el-input v-model="form.contact_name"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="contact_phone">
          <el-input v-model="form.contact_phone"></el-input>
        </el-form-item>
        <br />
        <br />
        <br />
        <el-form-item style="text-align: center; margin-left: -50px">
          <el-button size="mini" @click="onCancel">取消</el-button>
          <el-button size="mini" type="primary" @click="onSubmit">确认</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<script>
import { apiPublishInformation } from '@/api/customer'
export default {
  props: {
    id: {
      type: String,
      default: '',
    },
    phone: {
      type: String,
      default: '',
    },
    name: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      form: {
        company_id: this.id,
        plat_type: 1, // (0,"废旧"),(1,"聚拍")
        title: '', // 发布标题
        number: '', // 数量
        contact_name: this.name, // 联系人姓名
        contact_phone: this.phone, // 联系人电话
      },
      modelList: [],
      rules: {
        plat_type: [{ required: true, message: '发布平台不能为空', trigger: 'blur' }],
        title: [{ required: true, message: '信息简介不能为空', trigger: 'blur' }],
        number: [{ required: true, message: '数量不能为空', trigger: 'blur' }],
        contact_name: [{ required: true, message: '联系人不能为空', trigger: 'blur' }],
        contact_phone: [{ required: true, message: '联系电话不能为空', trigger: 'blur' }],
      },
      loading: false,
    }
  },
  mounted() {},
  methods: {
    onSubmit() {
      this.$refs.form.validate((flag) => {
        if (flag) {
          this.loading = true
          apiPublishInformation(this.form)
            .then((res) => {
              this.loading = false
              if (res.code === 200) {
                this.$message.success('操作成功！')
                setTimeout(() => {
                  this.$refs.form.resetFields()
                  this.$emit('close')
                }, 1000)
              }
            })
            .catch(() => {
              this.loading = false
            })
        }
      })
    },
    onCancel() {
      this.$refs.form.resetFields()
      this.$emit('close')
    },
  },
}
</script>
<style lang="scss" scoped></style>
